/**
 * Copyright 2011-2015 Newegg.com. All rights reserved.
 */
package com.arslan.cn.mail;

import java.net.URL;

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;

/**
 * 
 * @author zz33
 * @version $id:MailSender.java,v 0.1 2011-5-10 上午09:17:52 zz33 Exp$
 */
public class MailSender {
	public static void main(String[] args) throws Exception {
		sendSimpleEmail();
	}

	/**
	 * 发送简易邮件
	 * 
	 * @throws EmailException
	 */
	public static void sendSimpleEmail() throws EmailException {
		Email email = new SimpleEmail();
		email.setHostName("10.16.230.12");
		email.setSmtpPort(25);
		// email.setAuthenticator(new DefaultAuthenticator("zz33", "2wsx#EDC"));
		email.setTLS(true);
		email.setFrom("Sophie.S.Li@newegg.com", "CN MO HR");
		email.setSubject("hello,MM");
		email.setMsg("hello,MM. This is our test email");
		email.addTo("Sophie.S.Li@newegg.com");
		email.send();
	}

	public static void sendHtmlEmail() throws Exception {
		HtmlEmail email = new HtmlEmail();
		email.setHostName("10.16.230.12");
		email.addTo("Zorro.Q.Zhang@newegg.com", "John Doe");
		email.setFrom("admin@newegg.com", "CN MO HR");
		email.setSubject("");

		// embed the image and get the content id
		URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
		String cid = email.embed(url, "Apache logo");
		// set the html message
		email.setCharset("utf-8");
		email.setHtmlMsg("<html>这是封测试邮件</html>");

		// set the alternative message
		email.setTextMsg("Your email client does not support HTML messages");

		// send the email
		email.send();
	}
}
